<?php 
	header("Content-Type: text/html; charset=utf-8");
	set_time_limit(0);
?>


<html lang="zh" xml:lang="zh" xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	</head>
<body>
<form method="post" action="2cat-HIGH-naka.php">
	<table>
		<tr>
			<td colspan="2">
				二猫高解析二次壁-里版采集器
			</td>
		</tr>
		<tr>
			<td width="20%">
				分类地址:
			</td>
			<td>
				<input type="text" name="url" value="http://www.komica.tw/~hiso/pixmicat.php?mode=module&load=mod_catalog&page=0" />
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<input type="submit" value="GO" />
			</td>
		</tr>
	</table>
</form>
</body>
</html>


<?php
	
	//某个连接
	$link = $_POST['url'];
	if($link == ''){
		exit;
	}
	
	$path_info = pathinfo($_SERVER['SCRIPT_FILENAME']);
	$tmpjs_path  = $path_info['dirname'] . "/down.bat";
	$ft = fopen($tmpjs_path, 'w+');
	
   
	//预定义变量
	$default_pag_pre = "http://www.komica.tw/~hiso/pixmicat.php?mode=module&load=mod_catalog&page=";
	$default_0pag = "http://www.komica.tw/~hiso/pixmicat.php?mode=module&load=mod_catalog&page=0";
	$base_url = "http://www.komica.tw/~hiso/src/";
	$ext_name = ".jpg";
	
	echo "由于该站作了来源检测，请在下载时添加referer信息：<BR>
		--referer='http://www.komica.tw/~hiso/pixmicat.php?mode=module&load=mod_catalog'<BR><BR><BR><BR>
	";
	
	
	//获取首页面内容
	$content = file_get_contents($default_0pag);
	//获取总页面数
	$total_pgs = explode("</a>] </td><td><a href",$content);
	$total_pgs = explode(">",$total_pgs[0]);
	$total_pgs = $total_pgs[count($total_pgs) - 1];
	//总处理流程，遍历每页
	for ($i = 0; $i <= $total_pgs; $i++) {
		$current_pg_url = $default_pag_pre . $i;
		$piccurl = get_realpicurls(get_picurls(file_get_contents($current_pg_url)),$base_url,$ext_name);
		//生成下载命令连接
		foreach ($piccurl as $value) {
			$ln = "wget " . $value  ." --referer=\"http://www.komica.tw/~hiso/pixmicat.php?mode=module&load=mod_catalog\"\r\n";
			fwrite($ft, $ln);
		}
// 		fclose($ft);exit;
	}
	ob_end_flush();
	fclose($ft);
	//丢到文件里面去
	
	
	
	exit;

	//获取图片列表页面的图片显示页面链接
	function get_picurls($content) {
		$pic_links = array();
		$match_str = "/<div class=\"list\"><a href=\"src\/(.*)\" rel=/isU";
		preg_match_all($match_str,$content,$pic_links);
		return $pic_links[1];
	}
	//根据图片列表显示每个图片的下载链接
	function get_realpicurls($pic_links,$base_url,$ext_name) {
        $jp_url = array();
		foreach ($pic_links as $k) {
			$jp_url[] = $base_url . $k;
			echo $base_url . $k;
			echo "<BR>";
			ob_flush();
		}
		return $jp_url;
	}


?>
